<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="virtualfooddrive-inf.com.Address">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
			select 	ID, ADDRESS1, ADDRESS2, CITY, STATE_PROVINCE, POSTAL_CODE,
					COUNTRY, PHONE, FAX, ADDRESS_CAT_ID, USER_ORG_ID

			from dbo.ADDRESS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "Address").init();
			obj.ID = qRead.ID;
			obj.ADDRESS1 = qRead.ADDRESS1;
			obj.ADDRESS2 = qRead.ADDRESS2;
			obj.CITY = qRead.CITY;
			obj.STATE_PROVINCE = qRead.STATE_PROVINCE;
			obj.POSTAL_CODE = qRead.POSTAL_CODE;
			obj.COUNTRY = qRead.COUNTRY;
			obj.PHONE = qRead.PHONE;
			obj.FAX = qRead.FAX;
			obj.ADDRESS_CAT_ID = qRead.ADDRESS_CAT_ID;
			obj.USER_ORG_ID = qRead.USER_ORG_ID;
			return obj;
		</cfscript>
	</cffunction>



	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="Address">
		<cfset var qCreate="">

		<cfset var local1=arguments.bean.ADDRESS1>
		<cfset var local2=arguments.bean.ADDRESS2>
		<cfset var local3=arguments.bean.CITY>
		<cfset var local4=arguments.bean.STATE_PROVINCE>
		<cfset var local5=arguments.bean.POSTAL_CODE>
		<cfset var local6=arguments.bean.COUNTRY>
		<cfset var local7=arguments.bean.PHONE>
		<cfset var local8=arguments.bean.FAX>
		<cfset var local9=arguments.bean.ADDRESS_CAT_ID>
		<cfset var local10=0>

			<cfquery username="#request.username#" password="#request.password#" name="qCreate" datasource="nwharvest">
				insert into dbo.ADDRESS(ADDRESS1, ADDRESS2, CITY, STATE_PROVINCE, POSTAL_CODE, COUNTRY, PHONE, FAX, ADDRESS_CAT_ID, USER_ORG_ID)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local5#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local6#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local7#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local8#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local9#" cfsqltype="CF_SQL_INTEGER" null="#iif((local9 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local10#" cfsqltype="CF_SQL_INTEGER" null="#iif((local10 eq ""), de("yes"), de("no"))#" />
				)
				select @@Identity as pkID
			</cfquery>


		<cfscript>
			arguments.bean.ID = qCreate.pkID;
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="Address">
		<cfset var qUpdate="">

		<cfquery username="#request.username#" password="#request.password#" name="qUpdate" datasource="nwharvest" result="status">
			update dbo.ADDRESS
			set ADDRESS1 = <cfqueryparam value="#arguments.bean.ADDRESS1#" cfsqltype="CF_SQL_VARCHAR" />,
				ADDRESS2 = <cfqueryparam value="#arguments.bean.ADDRESS2#" cfsqltype="CF_SQL_VARCHAR" />,
				CITY = <cfqueryparam value="#arguments.bean.CITY#" cfsqltype="CF_SQL_VARCHAR" />,
				STATE_PROVINCE = <cfqueryparam value="#arguments.bean.STATE_PROVINCE#" cfsqltype="CF_SQL_VARCHAR" />,
				POSTAL_CODE = <cfqueryparam value="#arguments.bean.POSTAL_CODE#" cfsqltype="CF_SQL_VARCHAR" />,
				COUNTRY = <cfqueryparam value="#arguments.bean.COUNTRY#" cfsqltype="CF_SQL_VARCHAR" />,
				PHONE = <cfqueryparam value="#arguments.bean.PHONE#" cfsqltype="CF_SQL_VARCHAR" />,
				FAX = <cfqueryparam value="#arguments.bean.FAX#" cfsqltype="CF_SQL_VARCHAR" />,
				ADDRESS_CAT_ID = <cfqueryparam value="#arguments.bean.ADDRESS_CAT_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ADDRESS_CAT_ID eq ""), de("yes"), de("no"))#" />,
				USER_ORG_ID = <cfqueryparam value="#arguments.bean.USER_ORG_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.USER_ORG_ID eq ""), de("yes"), de("no"))#" />
			where ID = <cfqueryparam value="#arguments.bean.ID#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="Address">
		<cfset var qDelete="">

		<cfquery username="#request.username#" password="#request.password#" name="qDelete" datasource="nwharvest" result="status">
			delete
			from dbo.ADDRESS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.ID#" />
		</cfquery>

	</cffunction>


</cfcomponent>